package com.fmx.BookStore.domain;

import com.fmx.BookStore.core.domain.BaseEntity;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class SaleItem extends BaseEntity {
    // 主键
    private Long saleItemId;
    //书本
    private Book book;
    //书本ID
    private Long bookId;
    // 数量
    private int quantity;
    //订单ID
    private Long saleId;
    //价格
    private BigDecimal price;
    //状态
    private  String status;
    //删除标记
    private String delFlag;

    public SaleItem() {
    }

    public SaleItem(Long saleItemId, Book book, Long bookId, int quantity, Long saleId, BigDecimal price, String status, String delFlag) {
        this.saleItemId = saleItemId;
        this.book = book;
        this.bookId = bookId;
        this.quantity = quantity;
        this.saleId = saleId;
        this.price = price;
        this.status = status;
        this.delFlag = delFlag;
    }

    public Long getSaleItemId() {
        return saleItemId;
    }

    public void setSaleItemId(Long saleItemId) {
        this.saleItemId = saleItemId;
    }

    public Book getBook() {
        return book;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    public Long getBookId() {
        return bookId;
    }

    public void setBookId(Long bookId) {
        this.bookId = bookId;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Long getSaleId() {
        return saleId;
    }

    public void setSaleId(Long saleId) {
        this.saleId = saleId;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

    @Override
    public String toString() {
        return "SaleItem{" +
                "saleItemId=" + saleItemId +
                ", book=" + book +
                ", bookId=" + bookId +
                ", quantity=" + quantity +
                ", saleId=" + saleId +
                ", price=" + price +
                ", status='" + status + '\'' +
                ", delFlag='" + delFlag + '\'' +
                '}';
    }

    /**
     * 计算此项明细的总价
     */
    public BigDecimal getSubTotal(){
        BigDecimal subTotal = book.getPrice().multiply(new BigDecimal(quantity));
        return subTotal;
    }
}
